package com.qf.web;

import com.qf.pojo.PageBean;
import com.qf.pojo.User;
import com.qf.service.UserService;
import com.qf.service.serviceimpl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/findUserByPage")
public class FindUserByPageServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");//处理接受请求乱码
        response.setContentType("text/html;charset=utf-8");//处理响应乱码
        String cup = request.getParameter("currentPage");
        if(cup == null){
            cup = "1";
        }
        String ps = request.getParameter("pageSize");
        if(ps == null){
            ps = "2";
        }
        int currentPage = Integer.parseInt(cup);//当前页码
        int pageSize = Integer.parseInt(ps);//每页显示的条数
        /*System.out.println(currentPage);
        System.out.println(pageSize);*/
        UserService us = new UserServiceImpl();
        PageBean<User> ub = us.FindUserByPage(currentPage,pageSize);
        /*System.out.println(ub);*/
        if(ub != null){
            request.setAttribute("ub",ub);
            request.getRequestDispatcher("/admin/findall.jsp").forward(request,response);
        }
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
